/**
 * Created by ebalmes Oct 6, 2009 8:28:17 AM
 * 
 */
package gui;

import exceptions.DataException;
import gui.menus.PatientMenuBar;
import gui.panels.PatientDataPanel;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JFrame;

import listeners.IDataModelListener;
import model.DataModel;

public class MainFrame extends JFrame implements IDataModelListener
{
  private static int DEFAULT_WIDTH = 800;
  private static int DEFAULT_HEIGHT = 600;
  private static MainFrame mainFrame;
  private static Logger logger = Logger.getLogger(MainFrame.class.getName());
  private PatientDataPanel patientDataPanel;
  
  public MainFrame() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    setTitle("Patient Explorer");
    DataModel.getInstance().addDataModelListener(this);
    createGUI();
  }
  
  private void createGUI() {
    setJMenuBar(new PatientMenuBar(this));
    patientDataPanel = new PatientDataPanel();
    add(patientDataPanel);
    logger.log(Level.INFO, "Main GUI created.");
  }

  @Override
  public void dataModelCleaned() {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void dataModelUpdated() {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void patientSelected() throws DataException {
    showPatient();
    logger.log(Level.INFO, "Patient selected.");
  }
  
  private void showPatient() throws DataException {
    patientDataPanel.showPatient(DataModel.getInstance().getSelectedPatient());
  }
}
